package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.domain.EduBanner;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.service.TeacherService;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.common.service.BannerService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    BannerService bannerService;
    @Autowired
    TeacherService teacherService;
    @Autowired
    RedisTemplate redisTemplate;

    @Value("${redis.newCoursesKey}")
    String newCourses;

    @GetMapping("/getAllBanner")
    @Operation(summary = "查询全部轮播图")
    public ResultVo getAllBanner(){
        LambdaQueryWrapper<EduBanner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByAsc(EduBanner::getSort);
        Page<EduBanner> page = bannerService.page(new Page<>(1, 5),queryWrapper);
        return ResultVo.success("",page);
    }

    @GetMapping("/courseAndTeacher")
    @Operation(summary = "热门讲师")
    public ResultVo coursesAndTeacher(){
        HashMap map = new HashMap<>();
        List range = redisTemplate.opsForList().range(newCourses, 0, -1);
        List<EduTeacher> eduTeachers = teacherService.queryTeacherRank();
        map.put("eduList",range);
        map.put("teacherList",eduTeachers);
        return ResultVo.success(map);
    }
}
